Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine Value Observations #444

Merged
merged 12 commits into from
Nov 24, 2018
Merged

Conversation

groue
Copy link
Owner

@groue groue commented Nov 24, 2018

Sometimes you need to observe several requests at the same time. For example, you need to observe changes in both a team and its players.

When this happens, combine several observations together with the ValueObservation.combine(...) method:

// The two observed requests (the team and its players)
let teamRequest = Team.filter(key: 1)
let playersRequest = Player.filter(Column("teamId") == 1)

// Two observations
let teamObservation = ValueObservation.trackingOne(teamRequest)
let playersObservation = ValueObservation.trackingAll(playersRequest)

// The combined observation
let observation = ValueObservation.combine(teamObservation, playersObservation)

// Start tracking players and teams
let observer = observation.start(in: dbQueue) { team: Team?, players: [Player] in
    print("Team or players have changed.")
}

@groue groue added this to the GRDB 3.6.0 milestone Nov 24, 2018
@groue groue merged commit 6a10ad0 into development Nov 24, 2018
@groue groue deleted the feature/ValueObservationCombine branch November 24, 2018 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant